﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using Osobe;
using SkolskaUstanova;
using MolbeIPotvrde;

namespace ElektronskiDnevnik
{
    public partial class OdabirUcenika : Form
    {
        MySqlConnection conn;
        int odabraniPredmet, odabraniRazred, indikator;
        MySqlDataReader rdr = null;
        String odabraniUcenik, JMBG;
        public OdabirUcenika(MySqlConnection c, int predmet, int razred, String maticni, int ind)
        {
            InitializeComponent();
            conn = c;
            odabraniPredmet = predmet;
            odabraniRazred = razred;
            JMBG = maticni;
            indikator = ind;
        }

        private void Form14_Load(object sender, EventArgs e)
        {
            MySqlCommand cmd = new MySqlCommand("SELECT * FROM Ucenik WHERE Razred = " + odabraniRazred + ";", conn);
            try
            {
                rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    Button b = new Button();
                    b.TextImageRelation = TextImageRelation.ImageAboveText;
                    b.Image = global::ElektronskiDnevnik.Properties.Resources.student_icon1;
                    b.Text = Convert.ToString(rdr["JMBG"]) + "\n" + Convert.ToString(rdr["Ime"]) + " " + Convert.ToString(rdr["Prezime"]) ;
                    b.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                    b.AutoSize = true;
                    flowLayoutPanel1.Controls.Add(b);
                    b.Click += new System.EventHandler(this.b_Click);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Greska", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (rdr != null)
                    rdr.Close();
            }
           
            
        }
       private void b_Click(object sender, EventArgs e)
        {
            String s = ((Button)(sender)).Text;
            odabraniUcenik = s.Substring(0,13);
            if (indikator == 1)
            {
                PodnosenjeZahtjeva nova = new PodnosenjeZahtjeva(JMBG, odabraniUcenik, conn);
                nova.Show();
            }
            else
            {
                PregledZahtjeva nova = new PregledZahtjeva(JMBG, odabraniUcenik, conn);
                nova.Show();
            }
        }
    }
}
